/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaPrincipal.java
 *
 * Created on 16/08/2012, 10:39:01
 */
package GUI;

import controle.Controlador;
import controle.Malha;
import controle.Sinal;
import javax.swing.JRadioButton;

/**
 *
 * @author Lindemberg
 */
public class JanelaPrincipal extends javax.swing.JFrame {

    /** Creates new form JanelaPrincipal */
    public JanelaPrincipal() {
        initComponents();
        controlador = new Controlador();
        jtLog.setText(controlador.getLog());
        
        inicializar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtLog = new javax.swing.JTextArea();
        jToolBar1 = new javax.swing.JToolBar();
        jLabel6 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jbConectar = new javax.swing.JButton();
        jbDesconectar = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jrb0 = new javax.swing.JRadioButton();
        jrb1 = new javax.swing.JRadioButton();
        jrb2 = new javax.swing.JRadioButton();
        jrb3 = new javax.swing.JRadioButton();
        jrb7 = new javax.swing.JRadioButton();
        jrb6 = new javax.swing.JRadioButton();
        jrb5 = new javax.swing.JRadioButton();
        jrb4 = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        jtServidor = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jcbPorta = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        jrbe0 = new javax.swing.JRadioButton();
        jrbe1 = new javax.swing.JRadioButton();
        jrbe2 = new javax.swing.JRadioButton();
        jrbe3 = new javax.swing.JRadioButton();
        jrbe7 = new javax.swing.JRadioButton();
        jrbe6 = new javax.swing.JRadioButton();
        jrbe5 = new javax.swing.JRadioButton();
        jrbe4 = new javax.swing.JRadioButton();
        jrbMalhaAberta = new javax.swing.JRadioButton();
        jcbSinal = new javax.swing.JComboBox();
        jlSinal = new javax.swing.JLabel();
        jlcm = new javax.swing.JLabel();
        jtSP = new javax.swing.JTextField();
        jlSP = new javax.swing.JLabel();
        jrbMalhaFechada = new javax.swing.JRadioButton();
        jLabel13 = new javax.swing.JLabel();
        amplitude = new javax.swing.JSpinner();
        jbAplicarPortas = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel7 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        s0 = new javax.swing.JCheckBoxMenuItem();
        s1 = new javax.swing.JCheckBoxMenuItem();
        s2 = new javax.swing.JCheckBoxMenuItem();
        s3 = new javax.swing.JCheckBoxMenuItem();
        s4 = new javax.swing.JCheckBoxMenuItem();
        s5 = new javax.swing.JCheckBoxMenuItem();
        s6 = new javax.swing.JCheckBoxMenuItem();
        s7 = new javax.swing.JCheckBoxMenuItem();
        jMenu4 = new javax.swing.JMenu();
        e0 = new javax.swing.JCheckBoxMenuItem();
        e1 = new javax.swing.JCheckBoxMenuItem();
        e2 = new javax.swing.JCheckBoxMenuItem();
        e3 = new javax.swing.JCheckBoxMenuItem();
        e4 = new javax.swing.JCheckBoxMenuItem();
        e5 = new javax.swing.JCheckBoxMenuItem();
        e6 = new javax.swing.JCheckBoxMenuItem();
        e7 = new javax.swing.JCheckBoxMenuItem();
        jMenu5 = new javax.swing.JMenu();
        p1 = new javax.swing.JCheckBoxMenuItem();
        p2 = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jtLog.setColumns(20);
        jtLog.setRows(5);
        jScrollPane1.setViewportView(jtLog);

        jTabbedPane1.addTab("output", jScrollPane1);

        jToolBar1.setBorder(null);
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        jLabel6.setText("   ");
        jToolBar1.add(jLabel6);

        jLabel4.setBackground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Conexão:");
        jToolBar1.add(jLabel4);

        jbConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/greenBall.png"))); // NOI18N
        jbConectar.setFocusable(false);
        jbConectar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbConectar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbConectarActionPerformed(evt);
            }
        });
        jToolBar1.add(jbConectar);

        jbDesconectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/redBall.png"))); // NOI18N
        jbDesconectar.setFocusable(false);
        jbDesconectar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbDesconectar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jbDesconectar);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Painel de Controle"));

        jLabel1.setText("Saídas analógicas:");

        jrb0.setText("0");
        jrb0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb0ActionPerformed(evt);
            }
        });

        jrb1.setText("1");
        jrb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb1ActionPerformed(evt);
            }
        });

        jrb2.setText("2");
        jrb2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb2ActionPerformed(evt);
            }
        });

        jrb3.setText("3");
        jrb3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb3ActionPerformed(evt);
            }
        });

        jrb7.setText("7");
        jrb7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb7ActionPerformed(evt);
            }
        });

        jrb6.setText("6");
        jrb6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb6ActionPerformed(evt);
            }
        });

        jrb5.setText("5");
        jrb5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb5ActionPerformed(evt);
            }
        });

        jrb4.setText("4");
        jrb4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb4ActionPerformed(evt);
            }
        });

        jLabel2.setText("IP:");

        jtServidor.setText("localhost");

        jLabel3.setText("Porta:");

        jcbPorta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "20081", "20082" }));
        jcbPorta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPortaActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel5.setText("Entradas analógicas:");

        jrbe0.setText("0");
        jrbe0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe0ActionPerformed(evt);
            }
        });

        jrbe1.setText("1");
        jrbe1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe1ActionPerformed(evt);
            }
        });

        jrbe2.setText("2");
        jrbe2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe2ActionPerformed(evt);
            }
        });

        jrbe3.setText("3");
        jrbe3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe3ActionPerformed(evt);
            }
        });

        jrbe7.setText("7");
        jrbe7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe7ActionPerformed(evt);
            }
        });

        jrbe6.setText("6");
        jrbe6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe6ActionPerformed(evt);
            }
        });

        jrbe5.setText("5");
        jrbe5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe5ActionPerformed(evt);
            }
        });

        jrbe4.setText("4");
        jrbe4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe4ActionPerformed(evt);
            }
        });

        jrbMalhaAberta.setText("Malha aberta");
        jrbMalhaAberta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbMalhaAbertaActionPerformed(evt);
            }
        });

        jcbSinal.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Degrau", "Senoidal", "Quadrada", "Dente de serra", "Aleatório" }));

        jlSinal.setText("Sinal:");

        jlcm.setText("cm");

        jtSP.setText("0");

        jlSP.setText("Set-Point:");

        jrbMalhaFechada.setText("Malha fechada");
        jrbMalhaFechada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbMalhaFechadaActionPerformed(evt);
            }
        });

        jLabel13.setText("Amplitude:");

        amplitude.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(0.0f), Float.valueOf(0.0f), Float.valueOf(3.0f), Float.valueOf(0.1f)));

        jbAplicarPortas.setText("Aplicar");
        jbAplicarPortas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAplicarPortasActionPerformed(evt);
            }
        });

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel7.setText("Volts");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jrb4)
                            .addComponent(jrb0))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jrb1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb3))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jrb5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb7))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jrbe4)
                            .addComponent(jrbe0))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jrbe1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe3))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jrbe5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe7)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtServidor, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbPorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jrbMalhaAberta)
                    .addComponent(jrbMalhaFechada))
                .addGap(45, 45, 45)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jlSP)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtSP, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlcm))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jlSinal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbSinal, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(amplitude, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addGap(28, 28, 28)
                        .addComponent(jbAplicarPortas, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(0, 11, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrb0)
                            .addComponent(jrb1)
                            .addComponent(jrb2)
                            .addComponent(jrb3)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrb4)
                            .addComponent(jrb5)
                            .addComponent(jrb6)
                            .addComponent(jrb7))
                        .addGap(4, 4, 4)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrbe0)
                            .addComponent(jrbe1)
                            .addComponent(jrbe2)
                            .addComponent(jrbe3)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrbe4)
                            .addComponent(jrbe5)
                            .addComponent(jrbe6)
                            .addComponent(jrbe7)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2)
                                    .addComponent(jtServidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3)
                                    .addComponent(jcbPorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jrbMalhaAberta)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbMalhaFechada)))
                        .addGap(36, 50, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlSinal)
                            .addComponent(jcbSinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlSP)
                            .addComponent(jtSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlcm))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(amplitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jbAplicarPortas))))
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Gráficos"));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 861, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 259, Short.MAX_VALUE)
        );

        jMenu1.setText("Arquivo");

        jMenuItem1.setText("Conectar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText(" Configuração");

        jMenu3.setText("Saídas analógicas");

        s0.setSelected(true);
        s0.setText("Saída analógica 0");
        s0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s0ActionPerformed(evt);
            }
        });
        jMenu3.add(s0);

        s1.setSelected(true);
        s1.setText("Saída analógica 1");
        s1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s1ActionPerformed(evt);
            }
        });
        jMenu3.add(s1);

        s2.setSelected(true);
        s2.setText("Saída analógica 2");
        s2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s2ActionPerformed(evt);
            }
        });
        jMenu3.add(s2);

        s3.setSelected(true);
        s3.setText("Saída analógica 3");
        s3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s3ActionPerformed(evt);
            }
        });
        jMenu3.add(s3);

        s4.setSelected(true);
        s4.setText("Saída analógica 4");
        s4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s4ActionPerformed(evt);
            }
        });
        jMenu3.add(s4);

        s5.setSelected(true);
        s5.setText("Saída analógica 5");
        s5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s5ActionPerformed(evt);
            }
        });
        jMenu3.add(s5);

        s6.setSelected(true);
        s6.setText("Saída analógica 6");
        s6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s6ActionPerformed(evt);
            }
        });
        jMenu3.add(s6);

        s7.setSelected(true);
        s7.setText("Saída analógica 7");
        s7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s7ActionPerformed(evt);
            }
        });
        jMenu3.add(s7);

        jMenu2.add(jMenu3);

        jMenu4.setText("Entrada analógica");

        e0.setSelected(true);
        e0.setText("Entrada analógica 0");
        e0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e0ActionPerformed(evt);
            }
        });
        jMenu4.add(e0);

        e1.setSelected(true);
        e1.setText("Entrada analógica 1");
        e1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e1ActionPerformed(evt);
            }
        });
        jMenu4.add(e1);

        e2.setSelected(true);
        e2.setText("Entrada analógica 2");
        e2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e2ActionPerformed(evt);
            }
        });
        jMenu4.add(e2);

        e3.setSelected(true);
        e3.setText("Entrada analógica 3");
        e3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e3ActionPerformed(evt);
            }
        });
        jMenu4.add(e3);

        e4.setSelected(true);
        e4.setText("Entrada analógica 4");
        e4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e4ActionPerformed(evt);
            }
        });
        jMenu4.add(e4);

        e5.setSelected(true);
        e5.setText("Entrada analógica 5");
        e5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e5ActionPerformed(evt);
            }
        });
        jMenu4.add(e5);

        e6.setSelected(true);
        e6.setText("Entrada analógica 6");
        e6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e6ActionPerformed(evt);
            }
        });
        jMenu4.add(e6);

        e7.setSelected(true);
        e7.setText("Entrada analógica 7");
        e7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e7ActionPerformed(evt);
            }
        });
        jMenu4.add(e7);

        jMenu2.add(jMenu4);

        jMenu5.setText(" Porta");

        p1.setSelected(true);
        p1.setText(" 20081");
        p1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                p1ActionPerformed(evt);
            }
        });
        jMenu5.add(p1);

        p2.setSelected(true);
        p2.setText("20082");
        p2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                p2ActionPerformed(evt);
            }
        });
        jMenu5.add(p2);

        jMenu2.add(jMenu5);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 873, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 893, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        conectar();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void s0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s0ActionPerformed
        setSaida(0, s0.isSelected());
    }//GEN-LAST:event_s0ActionPerformed

    private void s1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s1ActionPerformed
        setSaida(1, s1.isSelected());
    }//GEN-LAST:event_s1ActionPerformed

    private void s2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s2ActionPerformed
        setSaida(2, s2.isSelected());      
    }//GEN-LAST:event_s2ActionPerformed

    private void s3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s3ActionPerformed
        setSaida(3, s3.isSelected());
    }//GEN-LAST:event_s3ActionPerformed

    private void s4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s4ActionPerformed
        setSaida(4, s4.isSelected());
    }//GEN-LAST:event_s4ActionPerformed

    private void s5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s5ActionPerformed
        setSaida(5, s5.isSelected());
    }//GEN-LAST:event_s5ActionPerformed

    private void s6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s6ActionPerformed
        setSaida(6, s6.isSelected());
    }//GEN-LAST:event_s6ActionPerformed

    private void s7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s7ActionPerformed
        setSaida(7, s7.isSelected());
    }//GEN-LAST:event_s7ActionPerformed

    private void e0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e0ActionPerformed
        setEntrada(0);
    }//GEN-LAST:event_e0ActionPerformed

    private void e1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e1ActionPerformed
        setEntrada(1);
    }//GEN-LAST:event_e1ActionPerformed

    private void e2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e2ActionPerformed
        setEntrada(2);
    }//GEN-LAST:event_e2ActionPerformed

    private void e3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e3ActionPerformed
        setEntrada(3);
    }//GEN-LAST:event_e3ActionPerformed

    private void e4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e4ActionPerformed
        setEntrada(4);
    }//GEN-LAST:event_e4ActionPerformed

    private void e5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e5ActionPerformed
        setEntrada(5);
    }//GEN-LAST:event_e5ActionPerformed

    private void e6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e6ActionPerformed
        setEntrada(6);
    }//GEN-LAST:event_e6ActionPerformed

    private void e7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e7ActionPerformed
        setEntrada(7);
    }//GEN-LAST:event_e7ActionPerformed

    private void p1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_p1ActionPerformed
        setPorta(20081);
    }//GEN-LAST:event_p1ActionPerformed

    private void p2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_p2ActionPerformed
        setPorta(20082);
    }//GEN-LAST:event_p2ActionPerformed

    private void jrb0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb0ActionPerformed
        setSaida(0, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb0ActionPerformed

    private void jrb1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb1ActionPerformed
        setSaida(1, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb1ActionPerformed

    private void jrb2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb2ActionPerformed
        setSaida(2, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb2ActionPerformed

    private void jrb3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb3ActionPerformed
        setSaida(3, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb3ActionPerformed

    private void jrb4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb4ActionPerformed
        setSaida(4, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb4ActionPerformed

    private void jrb5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb5ActionPerformed
        setSaida(5, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb5ActionPerformed

    private void jrb6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb6ActionPerformed
        setSaida(6, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb6ActionPerformed

    private void jrb7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb7ActionPerformed
        setSaida(7, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb7ActionPerformed

    private void jrbe0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe0ActionPerformed
        setEntrada(0);
    }//GEN-LAST:event_jrbe0ActionPerformed

    private void jrbe1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe1ActionPerformed
        setEntrada(1);
    }//GEN-LAST:event_jrbe1ActionPerformed

    private void jrbe2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe2ActionPerformed
        setEntrada(2);
    }//GEN-LAST:event_jrbe2ActionPerformed

    private void jrbe3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe3ActionPerformed
        setEntrada(3);
    }//GEN-LAST:event_jrbe3ActionPerformed

    private void jrbe4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe4ActionPerformed
        setEntrada(4);
    }//GEN-LAST:event_jrbe4ActionPerformed

    private void jrbe5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe5ActionPerformed
        setEntrada(5);
    }//GEN-LAST:event_jrbe5ActionPerformed

    private void jrbe6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe6ActionPerformed
        setEntrada(6);
    }//GEN-LAST:event_jrbe6ActionPerformed

    private void jrbe7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe7ActionPerformed
        setEntrada(7);
    }//GEN-LAST:event_jrbe7ActionPerformed

    private void jrbMalhaAbertaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbMalhaAbertaActionPerformed
//        habilitarCampos(true, false);
        setMalha(Malha.ABERTA);
    }//GEN-LAST:event_jrbMalhaAbertaActionPerformed

    private void jrbMalhaFechadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbMalhaFechadaActionPerformed
//        habilitarCampos(false, true);
        setMalha(Malha.FECHADA);
    }//GEN-LAST:event_jrbMalhaFechadaActionPerformed

    private void jcbPortaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPortaActionPerformed
        if(jcbPorta.getSelectedIndex() == 0){
            setPorta(20081);
        }else{
            setPorta(20082);
        }
    }//GEN-LAST:event_jcbPortaActionPerformed

    private void jbAplicarPortasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAplicarPortasActionPerformed
        setDadosMalhas();
        setServidor(jtServidor.getText());
    }//GEN-LAST:event_jbAplicarPortasActionPerformed

    private void jbConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConectarActionPerformed
        conectar();
    }//GEN-LAST:event_jbConectarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new JanelaPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner amplitude;
    private javax.swing.JCheckBoxMenuItem e0;
    private javax.swing.JCheckBoxMenuItem e1;
    private javax.swing.JCheckBoxMenuItem e2;
    private javax.swing.JCheckBoxMenuItem e3;
    private javax.swing.JCheckBoxMenuItem e4;
    private javax.swing.JCheckBoxMenuItem e5;
    private javax.swing.JCheckBoxMenuItem e6;
    private javax.swing.JCheckBoxMenuItem e7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton jbAplicarPortas;
    private javax.swing.JButton jbConectar;
    private javax.swing.JButton jbDesconectar;
    private javax.swing.JComboBox jcbPorta;
    private javax.swing.JComboBox jcbSinal;
    private javax.swing.JLabel jlSP;
    private javax.swing.JLabel jlSinal;
    private javax.swing.JLabel jlcm;
    private javax.swing.JRadioButton jrb0;
    private javax.swing.JRadioButton jrb1;
    private javax.swing.JRadioButton jrb2;
    private javax.swing.JRadioButton jrb3;
    private javax.swing.JRadioButton jrb4;
    private javax.swing.JRadioButton jrb5;
    private javax.swing.JRadioButton jrb6;
    private javax.swing.JRadioButton jrb7;
    private javax.swing.JRadioButton jrbMalhaAberta;
    private javax.swing.JRadioButton jrbMalhaFechada;
    private javax.swing.JRadioButton jrbe0;
    private javax.swing.JRadioButton jrbe1;
    private javax.swing.JRadioButton jrbe2;
    private javax.swing.JRadioButton jrbe3;
    private javax.swing.JRadioButton jrbe4;
    private javax.swing.JRadioButton jrbe5;
    private javax.swing.JRadioButton jrbe6;
    private javax.swing.JRadioButton jrbe7;
    private javax.swing.JTextArea jtLog;
    private javax.swing.JTextField jtSP;
    private javax.swing.JTextField jtServidor;
    private javax.swing.JCheckBoxMenuItem p1;
    private javax.swing.JCheckBoxMenuItem p2;
    private javax.swing.JCheckBoxMenuItem s0;
    private javax.swing.JCheckBoxMenuItem s1;
    private javax.swing.JCheckBoxMenuItem s2;
    private javax.swing.JCheckBoxMenuItem s3;
    private javax.swing.JCheckBoxMenuItem s4;
    private javax.swing.JCheckBoxMenuItem s5;
    private javax.swing.JCheckBoxMenuItem s6;
    private javax.swing.JCheckBoxMenuItem s7;
    // End of variables declaration//GEN-END:variables

    private Controlador controlador;
    
    private void inicializar(){
        zerarSelecaoSaidas();
        zerarSelecaoEntradas();
        zerarSelecaoPortas();
        
        setSaida(0, true); setEntrada(0);
        setServidor("localhost"); setPorta(20081);
        setMalha(Malha.ABERTA); setSinal(); setSetPoint(0); setAmplitude(0.0);
        controlador.setLogInteiro(controlador.getLog().substring(0, 41) + "\n");
        jtLog.setText(controlador.getLog());
    }

    private void setSaida(int saida, boolean selecionado){
        switch(saida){
            case 0: jrb0.setSelected(selecionado); s0.setSelected(selecionado); break;
            case 1: jrb1.setSelected(selecionado); s1.setSelected(selecionado); break;
            case 2: jrb2.setSelected(selecionado); s2.setSelected(selecionado); break;
            case 3: jrb3.setSelected(selecionado); s3.setSelected(selecionado); break;
            case 4: jrb4.setSelected(selecionado); s4.setSelected(selecionado); break;
            case 5: jrb5.setSelected(selecionado); s5.setSelected(selecionado); break;
            case 6: jrb6.setSelected(selecionado); s6.setSelected(selecionado); break;
            case 7: jrb7.setSelected(selecionado); s7.setSelected(selecionado); break;
        }
                
        controlador.setSaida(saida, selecionado);
        jtLog.setText(controlador.getLog());
    }
    
    private void zerarSelecaoSaidas() {
        s0.setSelected(false);
        s1.setSelected(false);
        s2.setSelected(false);
        s3.setSelected(false);
        s4.setSelected(false);
        s5.setSelected(false);
        s6.setSelected(false);
        s7.setSelected(false);
    }

    private void zerarSelecaoEntradas() {
        e0.setSelected(false); jrbe0.setSelected(false);
        e1.setSelected(false); jrbe1.setSelected(false);
        e2.setSelected(false); jrbe2.setSelected(false);
        e3.setSelected(false); jrbe3.setSelected(false);
        e4.setSelected(false); jrbe4.setSelected(false);
        e5.setSelected(false); jrbe5.setSelected(false);
        e6.setSelected(false); jrbe6.setSelected(false);
        e7.setSelected(false); jrbe7.setSelected(false);
    }
    
    private void zerarSelecaoPortas(){
        p1.setSelected(true);
        p2.setSelected(false);
    }

    private void setEntrada(int entrada) {
        zerarSelecaoEntradas();
        controlador.setEntrada(entrada);
        
        switch(entrada){
            case 0: e0.setSelected(true); jrbe0.setSelected(true); break;
            case 1: e1.setSelected(true); jrbe1.setSelected(true); break;
            case 2: e2.setSelected(true); jrbe2.setSelected(true); break;
            case 3: e3.setSelected(true); jrbe3.setSelected(true); break;
            case 4: e4.setSelected(true); jrbe4.setSelected(true); break;
            case 5: e5.setSelected(true); jrbe5.setSelected(true); break;
            case 6: e6.setSelected(true); jrbe6.setSelected(true); break;
            case 7: e7.setSelected(true); jrbe7.setSelected(true); break;
        }
        jtLog.setText(controlador.getLog());
    }

    private void setPorta(int porta) {
        controlador.setPorta(porta);
        if(porta == 20081){
            p1.setSelected(true);
            p2.setSelected(false);
            jcbPorta.setSelectedIndex(0);
        }else{
            p1.setSelected(false);
            p2.setSelected(true);
            jcbPorta.setSelectedIndex(1);
        }
        jtLog.setText(controlador.getLog());
    }

    private void setMalha(Malha malha) {
        controlador.setMalha(malha);
        jtLog.setText(controlador.getLog());
        
        if(malha == Malha.ABERTA){
            jrbMalhaAberta.setSelected(true);
            jrbMalhaFechada.setSelected(false);
        }else{
            jrbMalhaAberta.setSelected(false);
            jrbMalhaFechada.setSelected(true);
        }
    }

    private void setServidor(String text) {
        controlador.setServidor(text);
        jtLog.setText(controlador.getLog());
    }

    private void setDadosMalhas() {
        if(jrbMalhaAberta.isSelected()){
            setSinal();
        }else{
            controlador.setSetPoint(Double.parseDouble(jtSP.getText()));
        }
        jtLog.setText(controlador.getLog());
    }

    private void setSinal() {
        switch(jcbSinal.getSelectedIndex()){
            case 0: controlador.setSinal(Sinal.DEGRAU); break;
            case 1: controlador.setSinal(Sinal.ONDA_SENOIDAL); break;
            case 2: controlador.setSinal(Sinal.ONDA_QUADRADA); break;
            case 3: controlador.setSinal(Sinal.DENTE_DE_SERRA); break;
            case 4: controlador.setSinal(Sinal.ALEATORIO); break;
        }
        jtLog.setText(controlador.getLog());
    }

    private void conectar() {
        controlador.setLog("Tentando se conectar com o servidor "+ jtServidor.getText() + " ...");
        controlador.setServidor(jtServidor.getText());
        controlador.Conectar(jtServidor.getText());
        jtLog.setText(controlador.getLog());
    }

    private void setSetPoint(double setPoint) {
        controlador.setSetPoint(setPoint);
    }

    private void setAmplitude(double amplitude) {
        controlador.setAmplitude(amplitude);
    }
    
}
